import re

import requests

url = 'https://search.bilibili.com/all'

headers = {
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "accept-language": "zh-CN,zh;q=0.9",
    "cache-control": "no-cache",
    "pragma": "no-cache",
    "priority": "u=0, i",
    "sec-ch-ua-mobile": "?0",
    "sec-fetch-dest": "document",
    "sec-fetch-mode": "navigate",
    "sec-fetch-site": "same-origin",
    "sec-fetch-user": "?1",
    "upgrade-insecure-requests": "1",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
}

cookies = {
    "buvid3": "53234678-90E2-DD22-3F08-0B0956B7583A43004infoc",
    "b_nut": "1727863343",
    "_uuid": "21EFCFBF-64FC-4386-B149-9A748102CBF8D42696infoc",
    "buvid_fp": "d307428a92a34adb7c324b49436cefa6",
    "enable_web_push": "DISABLE",
    "home_feed_column": "5",
    "browser_resolution": "1475-696",
    "buvid4": "2C667E82-426C-E15A-D20C-0AC8566DCDA744549-024100210-EbEATEWb1D3yAr%2BtPZfANA%3D%3D",
    "b_lsid": "54333A34_192525B6162",
    "bsource": "search_bing",
    "header_theme_version": "CLOSE",
    "bili_ticket": "eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3MjgyMTc3NzQsImlhdCI6MTcyNzk1ODUxNCwicGx0IjotMX0.ukZvQoN1ybb9DBmwhZMHXxVlTHLDisXRdErxBZ4fqco",
    "bili_ticket_expires": "1728217714"
}

params = {
    "keyword": "蔡徐坤"
}

# 发送GET请求
resp = requests.get(url, headers=headers, cookies=cookies, params=params)

pattern = r'title:"([^"]+)".*?arcurl:"([^"]+)"'

# 使用findall方法找到所有匹配的项
matches = re.findall(pattern, resp.text)

for match in matches:
    print('Title: {0}, Arcurl: {1}'.format(match[0], match[1].replace(r"\u002F", "/")))
